package com.gupao.javavip.gof.strategy;

import com.gupao.javavip.gof.adapter.GetMaxNumberStrategyAdapter;

import java.util.HashMap;
import java.util.Map;

public class CalculatorService {

    private static final Map<CalculatorOperation, ICalculator> CALCULATOR_MAP = new HashMap<>();

    static {
        CALCULATOR_MAP.put(CalculatorOperation.ADDITION, new AdditionStrategy());
        CALCULATOR_MAP.put(CalculatorOperation.SUBTRACTION, new SubtractionStrategy());
        CALCULATOR_MAP.put(CalculatorOperation.MULTIPLICATION, new MultiplicationStrategy());
        CALCULATOR_MAP.put(CalculatorOperation.DIVISION, new DivisionStrategy());
        CALCULATOR_MAP.put(CalculatorOperation.GET_MAX_NUMBER, new GetMaxNumberStrategyAdapter());
    }

    //策略模式
    public int calculate(int num1, int num2, CalculatorOperation operation) {
        return CALCULATOR_MAP.get(operation).calculate(num1, num2);
    }
}
